/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mx.edu.itschapala.sistemas.septimo.Vista;

import com.sun.glass.events.KeyEvent;
import java.awt.Color;

import mx.edu.itschapala.sistemas.septimo.*;
import mx.edu.itschapala.sistemas.septimo.Control.*;
import mx.edu.itschapala.sistemas.septimo.Modelo.*;
import mx.edu.itschapala.sistemas.septimo.Modelo.*;
import mx.edu.itschapala.sistemas.septimo.Vista.enumeracion.*;

/**
 *
 * @author Sony
 */
public class ClienteCrearEditar extends javax.swing.JFrame {

    /**
     * Creates new form ProductoCrearEditar
     */
    
   private ProductoLnLocalCliente infoCliente;
    private TipoVentana tipoVentana;
    private Cliente cliente;
    
    public ClienteCrearEditar(Cliente cliente, ProductoLnLocalCliente infoCliente, TipoVentana tipoVentana) {
        this.infoCliente = infoCliente;
        this.tipoVentana = tipoVentana;
        this.cliente=cliente;
        
        
        initComponents();
    
        switch (tipoVentana) {
            case VENTANA_REGISTRO:
                jLabel1.setText("NUEVO PRODUCTO");
                break;
            case VENTANA_MODIFICAR:
                
                jLabel1.setText("MODIFICAR PRODUCTO");
                jTextField1.setEditable(false);
                
                jTextField1.setText(cliente.getNombre());
                //jTextField2.getText(cliente.getSexo()));
                jTextField3.setText(cliente.getId()+"");
                jTextField4.setText(cliente.getTelefono()+"");
                jTextField5.setText(cliente.getDireccion());
                break;
                
            case VENTANA_BUSQUEDA:
                jLabel1.setText("BUSCAR POR ID");
                jTextField1.setEditable(false);
                jTextField2.setEditable(false);
                jTextField4.setEditable(false);
                jTextField5.setEditable(false);
                ButtonCancelar.setVisible(false);
                break;
        }

    
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        Aceptar = new javax.swing.JButton();
        ButtonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridLayout(7, 1));

        jPanel1.setLayout(new java.awt.GridLayout(1, 1, 2, 0));

        jLabel1.setText("                                          Cliente");
        jPanel1.add(jLabel1);

        getContentPane().add(jPanel1);

        jPanel2.setLayout(new java.awt.GridLayout(1, 1, 2, 0));

        jLabel2.setText("  Nombre del Cliente");
        jPanel2.add(jLabel2);
        jPanel2.add(jTextField1);

        getContentPane().add(jPanel2);

        jPanel3.setLayout(new java.awt.GridLayout(1, 1, 2, 0));

        jLabel3.setText("Sexo");
        jPanel3.add(jLabel3);
        jPanel3.add(jTextField2);

        getContentPane().add(jPanel3);

        jPanel4.setLayout(new java.awt.GridLayout(1, 1, 2, 0));

        jLabel4.setText("Id");
        jPanel4.add(jLabel4);
        jPanel4.add(jTextField3);

        getContentPane().add(jPanel4);

        jPanel5.setLayout(new java.awt.GridLayout(1, 1, 2, 0));

        jLabel5.setText("Telefono");
        jPanel5.add(jLabel5);
        jPanel5.add(jTextField4);

        getContentPane().add(jPanel5);

        jPanel6.setLayout(new java.awt.GridLayout(1, 1, 2, 0));

        jLabel7.setText("Direcion");
        jPanel6.add(jLabel7);
        jPanel6.add(jTextField5);

        getContentPane().add(jPanel6);

        jPanel7.setLayout(new java.awt.GridLayout(1, 1, 2, 0));

        Aceptar.setText("Aceptar");
        Aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AceptarActionPerformed(evt);
            }
        });
        jPanel7.add(Aceptar);

        ButtonCancelar.setText("Cancelar");
        ButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonCancelarActionPerformed(evt);
            }
        });
        jPanel7.add(ButtonCancelar);

        getContentPane().add(jPanel7);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    //Aceptar
    private void AceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AceptarActionPerformed
       
          switch (tipoVentana) {
            case VENTANA_REGISTRO:
            Cliente c = new Cliente();
            
            c.setNombre(jTextField1.getText());
            c.setSexo(jTextField2.getText());
            c.setId(Integer.parseInt(jTextField3.getText()));
            c.setTelefono(Integer.parseInt(jTextField4.getText()));
            c.setDireccion(jTextField5.getText());
            
            infoCliente.Clienteregistrar(c);
            jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
            jTextField4.setText("");
            jTextField5.setText("");
            break;
            case VENTANA_BUSQUEDA:
            this.dispose();
            break;
            case VENTANA_MODIFICAR:
            c = new Cliente();
            c.setNombre(jTextField1.getText());
            c.setSexo(jTextField2.getText());
            c.setId(Integer.parseInt(jTextField3.getText()));
            c.setTelefono(Integer.parseInt(jTextField4.getText()));
            c.setDireccion(jTextField5.getText());
            
            infoCliente.Clienteregistrar(c);
            jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
            jTextField4.setText("");
            jTextField5.setText("");
            
            
            jTextField2.setEditable(false);
            jTextField3.setEditable(false);
            jTextField4.setEditable(false);
            jTextField5.setEditable(false);
            break;

        }
    }//GEN-LAST:event_AceptarActionPerformed

    private void ButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonCancelarActionPerformed
      this.dispose();
    }//GEN-LAST:event_ButtonCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ClienteCrearEditar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ClienteCrearEditar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ClienteCrearEditar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ClienteCrearEditar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Aceptar;
    private javax.swing.JButton ButtonCancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables
}
